using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
namespace Coding4Fun.Phone.Controls
{
	public class MetroFlow : ItemsControl
	{
		[CompilerGenerated]
		private sealed class Class25
		{
			public int int_0;
			public bool method_0(UIElement uielement_0)
			{
				return MetroFlow.smethod_5(uielement_0) == this.int_0;
			}
		}
		private const string string_0 = "LayoutRoot";
		private EventHandler<SelectionChangedEventArgs> eventHandler_0;
		private EventHandler<SelectionTapEventArgs> eventHandler_1;
		private GridLength gridLength_0 = new GridLength(48.0);
		private readonly GridLength gridLength_1 = new GridLength(1.0, 2);
		private Storyboard storyboard_0;
		private Grid grid_0;
		private int int_0;
		public static readonly DependencyProperty AnimationDurationProperty = DependencyProperty.Register("AnimationDuration", typeof(TimeSpan), typeof(MetroFlow), new PropertyMetadata(TimeSpan.FromMilliseconds(100.0)));
		public static readonly DependencyProperty SelectedColumnIndexProperty = DependencyProperty.Register("SelectedColumnIndex", typeof(int), typeof(MetroFlow), new PropertyMetadata(0, new PropertyChangedCallback(MetroFlow.smethod_0)));
		public static readonly DependencyProperty ExpandingWidthProperty = DependencyProperty.Register("ExpandingWidth", typeof(double), typeof(MetroFlow), new PropertyMetadata(new PropertyChangedCallback(MetroFlow.smethod_1)));
		public static readonly DependencyProperty CollapsingWidthProperty = DependencyProperty.Register("CollapsingWidth", typeof(double), typeof(MetroFlow), new PropertyMetadata(new PropertyChangedCallback(MetroFlow.smethod_2)));
		[CompilerGenerated]
		private static Func<UIElement, MetroFlowItem> func_0;
		public event EventHandler<SelectionChangedEventArgs> SelectionChanged
		{
			add
			{
				EventHandler<SelectionChangedEventArgs> eventHandler = this.eventHandler_0;
				EventHandler<SelectionChangedEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<SelectionChangedEventArgs> eventHandler3 = (EventHandler<SelectionChangedEventArgs>)Delegate.Combine(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange<EventHandler<SelectionChangedEventArgs>>(ref this.eventHandler_0, eventHandler3, eventHandler2);
				}
				while (eventHandler != eventHandler2);
			}
			remove
			{
				EventHandler<SelectionChangedEventArgs> eventHandler = this.eventHandler_0;
				EventHandler<SelectionChangedEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<SelectionChangedEventArgs> eventHandler3 = (EventHandler<SelectionChangedEventArgs>)Delegate.Remove(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange<EventHandler<SelectionChangedEventArgs>>(ref this.eventHandler_0, eventHandler3, eventHandler2);
				}
				while (eventHandler != eventHandler2);
			}
		}
		public event EventHandler<SelectionTapEventArgs> SelectionTap
		{
			add
			{
				EventHandler<SelectionTapEventArgs> eventHandler = this.eventHandler_1;
				EventHandler<SelectionTapEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<SelectionTapEventArgs> eventHandler3 = (EventHandler<SelectionTapEventArgs>)Delegate.Combine(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange<EventHandler<SelectionTapEventArgs>>(ref this.eventHandler_1, eventHandler3, eventHandler2);
				}
				while (eventHandler != eventHandler2);
			}
			remove
			{
				EventHandler<SelectionTapEventArgs> eventHandler = this.eventHandler_1;
				EventHandler<SelectionTapEventArgs> eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler<SelectionTapEventArgs> eventHandler3 = (EventHandler<SelectionTapEventArgs>)Delegate.Remove(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange<EventHandler<SelectionTapEventArgs>>(ref this.eventHandler_1, eventHandler3, eventHandler2);
				}
				while (eventHandler != eventHandler2);
			}
		}
		public TimeSpan AnimationDuration
		{
			get
			{
				return (TimeSpan)base.GetValue(MetroFlow.AnimationDurationProperty);
			}
			set
			{
				base.SetValue(MetroFlow.AnimationDurationProperty, value);
			}
		}
		public int SelectedColumnIndex
		{
			get
			{
				return (int)base.GetValue(MetroFlow.SelectedColumnIndexProperty);
			}
			set
			{
				base.SetValue(MetroFlow.SelectedColumnIndexProperty, value);
			}
		}
		public double ExpandingWidth
		{
			get
			{
				return (double)base.GetValue(MetroFlow.ExpandingWidthProperty);
			}
			set
			{
				base.SetValue(MetroFlow.ExpandingWidthProperty, value);
			}
		}
		public double CollapsingWidth
		{
			get
			{
				return (double)base.GetValue(MetroFlow.CollapsingWidthProperty);
			}
			set
			{
				base.SetValue(MetroFlow.CollapsingWidthProperty, value);
			}
		}
		public MetroFlow()
		{
			base.set_DefaultStyleKey(typeof(MetroFlow));
		}
		protected override void OnItemsChanged(NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs_0)
		{
			base.OnItemsChanged(notifyCollectionChangedEventArgs_0);
			if (this.grid_0 == null)
			{
				return;
			}
			if (this.SelectedColumnIndex >= base.get_Items().get_Count())
			{
				this.SelectedColumnIndex = base.get_Items().get_Count() - 1;
			}
			else
			{
				if (base.get_Items().get_Count() > 0 && this.SelectedColumnIndex < 0)
				{
					this.SelectedColumnIndex = 0;
				}
			}
			this.method_2();
		}
		protected override bool IsItemItsOwnContainerOverride(object item)
		{
			return item is MetroFlowData;
		}
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			this.grid_0 = (base.GetTemplateChild("LayoutRoot") as Grid);
			if (this.grid_0 != null && (!DesignerProperties.get_IsInDesignTool() || base.get_Items().get_Count() > 0))
			{
				this.method_2();
			}
		}
		private static void smethod_0(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			MetroFlow metroFlow = dependencyObject_0 as MetroFlow;
			if (metroFlow == null)
			{
				return;
			}
			if (dependencyPropertyChangedEventArgs_0.get_NewValue() == dependencyPropertyChangedEventArgs_0.get_OldValue())
			{
				return;
			}
			metroFlow.method_0((int)dependencyPropertyChangedEventArgs_0.get_OldValue());
		}
		private void method_0(int int_1)
		{
			this.int_0 = int_1;
			this.method_1();
			if (this.eventHandler_0 != null)
			{
				MetroFlowData metroFlowData = (base.get_Items().get_Count() <= 0 || this.SelectedColumnIndex < 0) ? null : ((MetroFlowData)base.get_Items().get_Item(this.SelectedColumnIndex));
				MetroFlowData metroFlowData2 = (base.get_Items().get_Count() <= 0 || this.int_0 < 0) ? null : ((MetroFlowData)base.get_Items().get_Item(this.int_0));
				List<MetroFlowData> list = new List<MetroFlowData>();
				list.Add(metroFlowData2);
				IList arg_96_0 = list;
				List<MetroFlowData> list2 = new List<MetroFlowData>();
				list2.Add(metroFlowData);
				SelectionChangedEventArgs selectionChangedEventArgs = new SelectionChangedEventArgs(arg_96_0, list2);
				this.eventHandler_0.Invoke(this, selectionChangedEventArgs);
			}
			this.method_5(this.grid_0, int_1);
		}
		private static void smethod_1(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			MetroFlow metroFlow = dependencyObject_0 as MetroFlow;
			if (metroFlow == null)
			{
				return;
			}
			Grid grid = metroFlow.grid_0;
			if (grid.get_ColumnDefinitions().get_Count() > 1)
			{
				MetroFlow.smethod_3(grid.get_ColumnDefinitions().get_Item(metroFlow.SelectedColumnIndex), (double)dependencyPropertyChangedEventArgs_0.get_NewValue());
			}
		}
		private static void smethod_2(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			MetroFlow metroFlow = dependencyObject_0 as MetroFlow;
			if (metroFlow == null)
			{
				return;
			}
			metroFlow.method_1();
			Grid grid = metroFlow.grid_0;
			if (grid.get_ColumnDefinitions().get_Count() > 1)
			{
				MetroFlow.smethod_3(grid.get_ColumnDefinitions().get_Item(metroFlow.int_0), (double)dependencyPropertyChangedEventArgs_0.get_NewValue());
			}
		}
		private void method_1()
		{
			if (this.int_0 >= base.get_Items().get_Count())
			{
				this.int_0 = base.get_Items().get_Count() - 1;
				if (this.SelectedColumnIndex == this.int_0)
				{
					this.int_0--;
				}
				if (this.int_0 < 0)
				{
					this.int_0 = 0;
				}
			}
		}
		private static void smethod_3(ColumnDefinition columnDefinition_0, double double_0)
		{
			if (columnDefinition_0 == null)
			{
				return;
			}
			columnDefinition_0.set_Width(new GridLength(double_0));
		}
		private void method_2()
		{
			Grid grid = this.grid_0;
			if (this.grid_0 != null && base.get_Items() != null)
			{
				grid.get_ColumnDefinitions().Clear();
				grid.get_Children().Clear();
				int num = 0;
				using (IEnumerator<object> enumerator = base.get_Items().GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						MetroFlowData metroFlowData = (MetroFlowData)enumerator.get_Current();
						bool flag = num == this.SelectedColumnIndex;
						ColumnDefinition columnDefinition = new ColumnDefinition();
						columnDefinition.set_Width((!flag) ? this.gridLength_0 : new GridLength(1.0, 2));
						ColumnDefinition columnDefinition2 = columnDefinition;
						grid.get_ColumnDefinitions().Add(columnDefinition2);
						MetroFlowItem metroFlowItem = new MetroFlowItem
						{
							ItemIndex = num + 1,
							ItemIndexOpacity = (double)((!flag) ? 1 : 0),
							ItemIndexVisibility = (!flag) ? 0 : 1,
							ImageSource = new BitmapImage(metroFlowData.ImageUri),
							ImageOpacity = (double)(flag ? 1 : 0),
							ImageVisibility = flag ? 0 : 1,
							Title = metroFlowData.Title,
							TitleOpacity = (double)(flag ? 1 : 0),
							TitleVisibility = flag ? 0 : 1
						};
						metroFlowItem.SetValue(Grid.ColumnProperty, num);
						metroFlowItem.add_Tap(new EventHandler<GestureEventArgs>(this.method_3));
						grid.get_Children().Add(metroFlowItem);
						num++;
					}
				}
				return;
			}
		}
		private void method_3(object sender, GestureEventArgs e)
		{
			MetroFlowItem metroFlowItem = sender as MetroFlowItem;
			if (metroFlowItem == null)
			{
				return;
			}
			int selectedColumnIndex = this.SelectedColumnIndex;
			this.SelectedColumnIndex = MetroFlow.smethod_5(metroFlowItem);
			if (selectedColumnIndex != this.SelectedColumnIndex)
			{
				return;
			}
			if (this.eventHandler_1 != null)
			{
				this.eventHandler_1.Invoke(this, new SelectionTapEventArgs
				{
					Index = this.SelectedColumnIndex,
					Data = (MetroFlowData)base.get_Items().get_Item(this.SelectedColumnIndex)
				});
			}
		}
		private void method_4(int int_1)
		{
			if (this.storyboard_0 != null && this.storyboard_0.GetCurrentState() == null)
			{
				this.storyboard_0.Stop();
				this.method_8(int_1);
				return;
			}
		}
		private void method_5(Grid grid_1, int int_1)
		{
			if (grid_1 != null && grid_1.get_ColumnDefinitions().get_Count() >= this.SelectedColumnIndex)
			{
				this.method_4(int_1);
				Storyboard storyboard = new Storyboard();
				MetroFlowItem metroFlowItem = MetroFlow.smethod_4(grid_1, this.SelectedColumnIndex);
				MetroFlowItem metroFlowItem2 = MetroFlow.smethod_4(grid_1, int_1);
				if (metroFlowItem != null)
				{
					metroFlowItem.ImageVisibility = 0;
					metroFlowItem.TitleVisibility = 0;
					this.method_6(storyboard, metroFlowItem, "ImageOpacity", 1.0, metroFlowItem.ImageOpacity);
					this.method_6(storyboard, metroFlowItem, "TitleOpacity", 1.0, metroFlowItem.TitleOpacity);
					this.method_6(storyboard, metroFlowItem, "ItemIndexOpacity", 0.0, metroFlowItem.ItemIndexOpacity);
				}
				if (metroFlowItem2 != null)
				{
					metroFlowItem2.ItemIndexVisibility = 0;
					this.method_6(storyboard, metroFlowItem2, "ImageOpacity", 0.0, metroFlowItem2.ImageOpacity);
					this.method_6(storyboard, metroFlowItem2, "TitleOpacity", 0.0, metroFlowItem2.TitleOpacity);
					this.method_6(storyboard, metroFlowItem2, "ItemIndexOpacity", 1.0, metroFlowItem2.ItemIndexOpacity);
				}
				double value = this.gridLength_0.get_Value();
				string string_ = "CollapsingWidth";
				DoubleAnimation doubleAnimation = this.method_6(storyboard, this, string_, value, 0.0);
				double value2 = this.gridLength_0.get_Value();
				string string_2 = "ExpandingWidth";
				DoubleAnimation doubleAnimation2 = this.method_6(storyboard, this, string_2, 0.0, value2);
				storyboard.add_Completed(new EventHandler(this.method_9));
				if (metroFlowItem2 != null)
				{
					double actualWidth = metroFlowItem2.get_ActualWidth();
					doubleAnimation2.set_To(new double?(actualWidth));
					doubleAnimation.set_From(new double?(actualWidth));
				}
				base.UpdateLayout();
				this.storyboard_0 = storyboard;
				this.storyboard_0.Begin();
				return;
			}
		}
		private DoubleAnimation method_6(Storyboard storyboard_1, DependencyObject dependencyObject_0, string string_1, double double_0 = 0.0, double double_1 = 0.0)
		{
			DoubleAnimation doubleAnimation = new DoubleAnimation();
			doubleAnimation.set_To(new double?(double_0));
			doubleAnimation.set_From(new double?(double_1));
			doubleAnimation.set_Duration(this.AnimationDuration);
			DoubleAnimation doubleAnimation2 = doubleAnimation;
			Storyboard.SetTarget(doubleAnimation2, dependencyObject_0);
			Storyboard.SetTargetProperty(doubleAnimation2, new PropertyPath(string_1, new object[0]));
			storyboard_1.get_Children().Add(doubleAnimation2);
			return doubleAnimation2;
		}
		private static MetroFlowItem smethod_4(Panel panel_0, int int_1)
		{
			MetroFlow.Class25 @class = new MetroFlow.Class25();
			@class.int_0 = int_1;
			return Enumerable.SingleOrDefault<UIElement>(Enumerable.Where<UIElement>(panel_0.get_Children(), new Func<UIElement, bool>(@class.method_0))) as MetroFlowItem;
		}
		private static int smethod_5(DependencyObject dependencyObject_0)
		{
			return (int)dependencyObject_0.GetValue(Grid.ColumnProperty);
		}
		private void method_7()
		{
			this.method_8(this.SelectedColumnIndex);
		}
		private void method_8(int int_1)
		{
			for (int i = 0; i < this.grid_0.get_ColumnDefinitions().get_Count(); i++)
			{
				this.grid_0.get_ColumnDefinitions().get_Item(i).set_Width((i != int_1) ? this.gridLength_0 : this.gridLength_1);
			}
			IEnumerable<UIElement> arg_6B_0 = this.grid_0.get_Children();
			if (MetroFlow.func_0 == null)
			{
				MetroFlow.func_0 = new Func<UIElement, MetroFlowItem>(MetroFlow.smethod_7);
			}
			using (IEnumerator<MetroFlowItem> enumerator = Enumerable.Select<UIElement, MetroFlowItem>(arg_6B_0, MetroFlow.func_0).GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					MetroFlowItem current = enumerator.get_Current();
					MetroFlow.smethod_6(current, MetroFlow.smethod_5(current) == int_1);
				}
			}
			base.UpdateLayout();
		}
		private static void smethod_6(MetroFlowItem metroFlowItem_0, bool bool_0)
		{
			if (metroFlowItem_0 == null)
			{
				return;
			}
			metroFlowItem_0.ImageVisibility = (metroFlowItem_0.TitleVisibility = (bool_0 ? 0 : 1));
			metroFlowItem_0.TitleOpacity = (metroFlowItem_0.ImageOpacity = (double)(bool_0 ? 1 : 0));
			metroFlowItem_0.ItemIndexVisibility = (bool_0 ? 1 : 0);
			metroFlowItem_0.ItemIndexOpacity = (double)(bool_0 ? 0 : 1);
		}
		[CompilerGenerated]
		private void method_9(object sender, EventArgs e)
		{
			this.method_7();
		}
		[CompilerGenerated]
		private static MetroFlowItem smethod_7(UIElement uielement_0)
		{
			return uielement_0 as MetroFlowItem;
		}
	}
}
